#include <stdio.h>
#include <string.h>
typedef struct _student {
    int score;
    int grade;
    char name[32];
} Student;
int bijiao(const void* a, const void* b) {
    const Student* studenta = (const Student*)a;
    const Student* studentb = (const Student*)b;
    if (studenta->grade != studentb->grade) {
        return studenta->grade - studentb->grade;
    }
    else if (studenta->score != studentb->score) {
        return studenta->score - studentb->score;
    }
    else {
        return strcmp(studentb->name, studenta->name);
    }
}
void BubbleSort(void* base, size_t count, size_t width, int (*comp)(const void*, const void*)) {
	float zhongzhi;
    char* arr = (char*)base;
    for (size_t i = 0; i < count - 1; i++) {
    	zhongzhi=0.0f;
        for (size_t j = 0; j < count - i - 1; j++) {
            if (comp(arr + j * width, arr + (j + 1) * width) < 0) {
                char temp[width];
                memcpy(temp, arr + j * width, width);
                memcpy(arr + j * width, arr + (j + 1) * width, width);
                memcpy(arr + (j + 1) * width, temp, width);
                zhongzhi=1.0f;
            }
        }
        if(!zhongzhi){
        	continue;
		}
    }
}
int main() {
    Student xuesheng[10] = {
        {90,4,"anna"},
        {90,4,"duo"},
        {100,3,"tom"},
        {100,4,"lily"},
        {30,2,"zzs"	},
        {55,5,"yyy"	},
        {66,1,"sss"	},
        {78,3,"ppp"	},
        {100,5,"ooo"},
        {95,3,"eee"	},
    };
    BubbleSort(xuesheng, 10, sizeof(Student), bijiao);
    for (int i = 0; i < 10; i++) {
        printf("{ %d, %d, %s }\n", xuesheng[i].score,
            xuesheng[i].grade,
            xuesheng[i].name);
    }
    return 0;
};